package ntut.andengine.game;

import org.anddev.andengine.engine.handler.IUpdateHandler;
import org.anddev.andengine.entity.scene.Scene;
import org.anddev.andengine.entity.sprite.Sprite;
import org.anddev.andengine.opengl.texture.TextureOptions;
import org.anddev.andengine.opengl.texture.bitmap.BitmapTexture;
import org.anddev.andengine.opengl.texture.bitmap.BitmapTextureRegionFactory;
import org.anddev.andengine.opengl.texture.region.TextureRegion;

public class LogoActivity extends GameScene{

	private static final int CAMERA_WIDTH = 480;
	private static final int CAMERA_HEIGHT = 800;
	
	private TextureRegion mNTUTLogoTextureRegion;

	@Override
	public void onLoadResources() {
		super.onLoadResources();
		
		BitmapTexture bitmapTexture = new BitmapTexture(256, 128, TextureOptions.BILINEAR_PREMULTIPLYALPHA);
		mNTUTLogoTextureRegion = BitmapTextureRegionFactory.createFromAsset(bitmapTexture, this, "ntut_logo.png", 0, 0);
		mEngine.getTextureManager().loadTexture(bitmapTexture);
	}

	@Override
	public Scene onLoadScene() {
		final int centerX = (CAMERA_WIDTH - this.mNTUTLogoTextureRegion.getWidth()) / 2;
		final int centerY = (CAMERA_HEIGHT - this.mNTUTLogoTextureRegion.getHeight()) / 2;
		
		final Sprite ntutLogo = new Sprite(centerX, centerY, this.mNTUTLogoTextureRegion);
		
		mScene = new Scene();
		mScene.attachChild(ntutLogo);
		
		/* UPDATE */	
		mScene.registerUpdateHandler(new IUpdateHandler(){
			float time;
			
			@Override
			public void onUpdate(float pSecondsElapsed) {
				time += pSecondsElapsed;
				
				if(time > 3){
					startActivity(LogoActivity.this, GameInit.class);				
				}
			}

			@Override
			public void reset() {
				// TODO Auto-generated method stub
				
			}
			
		});
		
		return mScene;
	}

}
